<template>
  <a-table size="small" rowKey="id" :columns="columns" :data-source="dataSource" :pagination="false" :loading="loading" bordered>
    <template slot="baseClasstime" slot-scope="text, record">
      <editable-cell :text="text" @change="onCellChange(record, 'baseClasstime', $event)" />
    </template>
    <template slot="basePoints" slot-scope="text, record">
      <editable-cell :text="text" @change="onCellChange(record, 'basePoints', $event)" />
    </template>
  </a-table>
</template>

<script>
import EditableCell from '@views/gfxy/config/EditableCell'
import { getAction, httpAction } from '@api/manage'
export default {
  name: "baseClasstimeConfig",
  components: {
    EditableCell,
  },
  data(){
    return {
      loading : false,
      dataSource:[],
      columns:[
        {
          title: '职称级别',
          dataIndex: 'titleLeave_dictText',
        },
        {
          title: '基础课时',
          dataIndex: 'baseClasstime',
          scopedSlots: { customRender: 'baseClasstime' },
        },
        {
          title: '基础积分',
          dataIndex: 'basePoints',
          scopedSlots: { customRender: 'basePoints' },
        },
      ],
      url:{
        list:'/config/configBaseclasstime/list',
        edit: "/config/configBaseclasstime/edit",
      }
    }
  },
  methods: {
    onCellChange(record, dataIndex, value) {
      record[dataIndex] = value;
      this.saveData(record);
    },
    loadData(){
      if(!this.url.list){
        this.$message.error("请设置url.list属性!")
        return
      }
      this.loading = true;
      getAction(this.url.list, {}).then((res) => {
        if (res.success) {
          //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records||res.result;
          console.log(this.dataSource)

          //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        }
        if(res.code===510){
          this.$message.warning(res.message)
        }
        this.loading = false;
      })
    },
    saveData(data){
      console.log(data)
      this.loading = true;
      httpAction(this.url.edit, data, 'put').then((res) => {
        if (res.success) {
          this.$message.success(res.message)

        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.loading = false
      })
    }
  },
  created(){
    this.loadData();
  }
}
</script>

<style scoped>


</style>